﻿namespace Leetcode.N0017;
public class Solution
{
    public IList<string> LetterCombinations(string digits)
    {

        if (string.IsNullOrEmpty(digits))
        {
            return new List<string>();
        }

        var lettersMap = new string[] { "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
        var ans = new List<string>();
        foreach (var item in digits)
        {
            var letters = lettersMap[item - '2'];
            if (ans.Count == 0)
            {
                foreach (var letter in letters)
                {
                    ans.Add(new string(letter, 1));
                }
            }
            else
            {
                var newAns = new List<string>();
                foreach (var ansItem in ans)
                {
                    foreach (var letter in letters)
                    {
                        newAns.Add($"{ansItem}{letter}");
                    }
                }
                ans = newAns;
            }
        }
        return ans;
    }
}